<template>
  <q-page class="q-pa-md">
    <div class="row items-center">
      <div class="q-pb-md text-h5">{{ pageTitle }}</div>
      <q-space></q-space>
      <search-bar-toggle-btn v-model="searchBarVisibility"></search-bar-toggle-btn>
    </div>
    <!--查询-->
    <div class="q-pa-sm shadow-2 q-mb-md items-center" v-show="searchBarVisibility">
      <div class="row q-col-gutter-sm">
        <div class="col-12 col-sm-6 col-md-4 col-lg-3 row q-col-gutter-sm">
          <div class="col-4 text-right searchbar-label">仓库</div>
          <div class="col-8">
            <simple-filter-select :options="$d.whDropdownList" :readonly="listDataLoadingState" :use-filter="false"
              option-label="whName" option-value="whId" v-model="fpsReq.whId" @update:model-value="onWhChanged" />
          </div>
        </div>
        <div class="col-12 col-sm-6 col-md-4 col-lg-3 row q-col-gutter-sm">
          <div class="col-4 text-right searchbar-label">货主</div>
          <div class="col-8">
            <simple-filter-select :options="$d.storerDropdownList" option-label="abbrName" option-value="mfId"
              v-model="fpsReq.storerId" :auto-select-single-option="false" :readonly="listDataLoadingState" />
          </div>
        </div>
        <div class="col-12 col-sm-6 col-md-4 col-lg-3 row q-col-gutter-sm">
          <div class="col-4 text-right searchbar-label">来源储区</div>
          <div class="col-8">
            <simple-filter-select v-model="fpsReq.fZoneId" :options="$d.zoneDropdownList" :use-filter="false"
              :auto-select-single-option="false" :readonly="listDataLoadingState" option-label="zoneName"
              option-value="zoneId" @update:model-value="fpsReq.fLocId = null" />
          </div>
        </div>
        <div class="col-12 col-sm-6 col-md-4 col-lg-3 row q-col-gutter-sm">
          <div class="col-4 text-right searchbar-label">目的储区</div>
          <div class="col-8">
            <simple-filter-select v-model="fpsReq.tZoneId" :options="$d.zoneDropdownList" :use-filter="false"
              :auto-select-single-option="false" :readonly="listDataLoadingState" option-label="zoneName"
              option-value="zoneId" @update:model-value="fpsReq.tLocId = null" />
          </div>
        </div>
        <div class="col-12 col-sm-6 col-md-4 col-lg-3 row q-col-gutter-sm" v-if="$d.actualFieldShown.fLocId?.isShown && fpsInfo.filtersInfo?.fLocId?.show">
          <div class="col-4 text-right searchbar-label">来源储位</div>
          <div class="col-8">
            <simple-filter-select v-model="fpsReq.fLocId" :use-filter="false"
              :auto-select-single-option="false" :readonly="listDataLoadingState"
              :options="$d.fLocIdDropdownList"
              option-label="loc"
              option-value="locId"
              server-side-url="/wms/basic/loc/get-loc-simple-list"
              search-content-field="loc"
              resp-data-field="locs"
              :req-params="{pageNo:1,pageSize:10,whId:fpsReq.whId,zoneId:fpsReq.fZoneId}"
            />
          </div>
        </div>
        <div class="col-12 col-sm-6 col-md-4 col-lg-3 row q-col-gutter-sm" v-if="$d.actualFieldShown.tLocId?.isShown && fpsInfo.filtersInfo?.tLocId?.show">
          <div class="col-4 text-right searchbar-label">目的储位</div>
          <div class="col-8">
            <simple-filter-select v-model="fpsReq.tLocId" :use-filter="false"
              :auto-select-single-option="false" :readonly="listDataLoadingState"
              :options="$d.tLocIdDropdownList"
              option-label="loc"
              option-value="locId"
              server-side-url="/wms/basic/loc/get-loc-simple-list"
              search-content-field="loc"
              resp-data-field="locs"
              :req-params="{pageNo:1,pageSize:10,whId:fpsReq.whId,zoneId:fpsReq.tZoneId}"
            />
          </div>
        </div>
        <div class="col-12 col-sm-6 col-md-4 col-lg-3 row q-col-gutter-sm" v-if="$d.actualFieldShown.sku?.isShown && fpsInfo.filtersInfo?.sku?.show">
          <div class="col-4 text-right searchbar-label">料号</div>
          <div class="col-8">
            <wm-sku-selector :sku="fpsReq.sku" @sku-selected="onSkuSelected"
              v-model="fpsReq.skuId" :storer-id="fpsReq.storerId" :readonly="listDataLoadingState"></wm-sku-selector>
          </div>
        </div>
        <div class="col-12 col-sm-6 col-md-4 col-lg-3 row q-col-gutter-sm" v-if="$d.actualFieldShown.fLpn?.isShown && fpsInfo.filtersInfo?.fLpn?.show">
          <div class="col-4 text-right searchbar-label">来源栈板</div>
          <div class="col-8">
            <easy-input v-model="fpsReq.fLpn" :readonly="listDataLoadingState" @keyup.enter="loadListData(2)" ></easy-input>
          </div>
        </div>
        <div class="col-12 col-sm-6 col-md-4 col-lg-3 row q-col-gutter-sm" v-if="$d.actualFieldShown.tLpn?.isShown && fpsInfo.filtersInfo?.tLpn?.show">
          <div class="col-4 text-right searchbar-label">目的栈板</div>
          <div class="col-8">
            <easy-input v-model="fpsReq.tLpn" :readonly="listDataLoadingState" @keyup.enter="loadListData(2)" ></easy-input>
          </div>
        </div>
        <div class="col-12 col-sm-6 col-md-4 col-lg-3 row q-col-gutter-sm" v-if="$d.actualFieldShown.moveId?.isShown && fpsInfo.filtersInfo?.moveId?.show">
          <div class="col-4 text-right searchbar-label">移库单ID</div>
          <div class="col-8">
            <easy-input v-model="fpsReq.moveId" :readonly="listDataLoadingState" @keyup.enter="loadListData(2)" ></easy-input>
          </div>
        </div>
        <div class="col-12 col-sm-6 col-md-4 col-lg-3 row q-col-gutter-sm" v-if="$d.actualFieldShown.invLocId?.isShown && fpsInfo.filtersInfo?.invLocId?.show">
          <div class="col-4 text-right searchbar-label">库存ID</div>
          <div class="col-8">
            <easy-input v-model="fpsReq.invLocId" :readonly="listDataLoadingState" @keyup.enter="loadListData(2)" ></easy-input>
          </div>
        </div>
        <div class="col-12 col-sm-6 col-md-4 col-lg-3 row q-col-gutter-sm" v-if="$d.actualFieldShown.vLot?.isShown && fpsInfo.filtersInfo?.vLot?.show">
          <div class="col-4 text-right searchbar-label">LPN</div>
          <div class="col-8">
            <easy-input v-model="fpsReq.vLot" :readonly="listDataLoadingState" @keyup.enter="loadListData(2)" ></easy-input>
          </div>
        </div>
        <div class="col-12 col-sm-6 col-md-4 col-lg-3 row q-col-gutter-sm" v-if="$d.actualFieldShown.lot?.isShown && fpsInfo.filtersInfo?.lot?.show">
          <div class="col-4 text-right searchbar-label">批号</div>
          <div class="col-8">
            <easy-input v-model="fpsReq.lot" :readonly="listDataLoadingState" @keyup.enter="loadListData(2)" ></easy-input>
          </div>
        </div>
        <div class="col-12 col-sm-6 col-md-4 col-lg-3 row q-col-gutter-sm" v-if="$d.actualFieldShown.isMoved?.isShown && fpsInfo.filtersInfo?.isMoved?.show">
          <div class="col-4 text-right searchbar-label">是否移库完成</div>
          <q-toggle :toggle-indeterminate="true" class="q-mt-xs" dense v-model="fpsReq.isMoved"
            :disable="listDataLoadingState" @update:model-value="loadListData(2)" />
        </div>
      </div>
      <div class="row q-pt-sm">
        <div class="q-mr-sm">
          <q-btn :disable="listDataLoadingState" @click="loadListData(2)" color="primary" icon="search" label="查询" />
        </div>
        <div>
          <filter-options-cfg v-model:option-list="fpsInfo.filtersInfo"
            @update-filter-options-for-save="fpsAssist.saveFilterOptions">
          </filter-options-cfg>
        </div>
      </div>
    </div>
    <div class="shadow-2">
      <q-table :columns="fpsInfo.columnsInfo" :rows="$d.tableData" :hide-pagination="true"
        :loading="listDataLoadingState" row-key="moveLineId"
        :visible-columns="fpsInfo.visibleColumns" @request="fpsAssist.onDataTableRequest"
        v-model:pagination="fpsInfo.paginationInfo" selection="multiple" v-model:selected="$d.selectedItems"
        binary-state-sort color="primary" dense flat separator="cell">
        <template v-slot:top="props">
          <!--功能按钮-->
          <div class="q-gutter-sm">
            <q-btn @click="onUpdateLabelManagement" color="primary" icon="sync" label="批量更新贴标工序管理信息"
              v-if="fx.hasModifyRight('Wms.Inv.InvMove.Edit')" :disable="$d.selectedItems.length === 0" />
          </div>
          <q-space />
<!--          <q-btn @click="downloadListExcel" dense flat icon="save_alt" title="导出Excel(受最大条数上限限制,默认10000,有疑问可联系软件供应商)" />-->
          <table-col-options-cfg v-model:visible-columns="fpsInfo.visibleColumns"
            v-model:table-columns="fpsInfo.columnsInfo" class="q-mx-sm"
            @update-col-options-for-save="fpsAssist.saveColOptions"></table-col-options-cfg>
          <q-btn :icon="props.inFullscreen ? 'fullscreen_exit' : 'fullscreen'" :ripple="false"
            :title="props.inFullscreen ? '退出全屏' : '全屏显示'" dense flat @click="props.toggleFullscreen" />
        </template>
        <template v-slot:no-data>
          <span class="full-width text-center">
            <q-icon name="error_outline" />
            无数据
            <q-btn flat icon="refresh" :loading="listDataLoadingState"
              :disable="listDataLoadingState" dense title="刷新" size="sm" class="q-ml-sm" @click="loadListData"></q-btn>
            </span>
        </template>
        <!--状态列插槽-->
        <template v-slot:body-cell-moveState="props">
          <q-td :props="props" auto-width>
            <q-badge :color="fx.fmt.fmtMoveStateColor(props.row.moveState)"
              :label="fx.fmt.fmtMoveState(props.row.moveState)" />
          </q-td>
        </template>
        <template v-slot:bottom>
          <paging-bar :loading-state="listDataLoadingState" :pageNo="fpsReq.pageNo" :pageSize="fpsReq.pageSize"
            :totalAmount="fpsInfo.totalAmount" @pagesize-changed="fpsAssist.onPageSizeChanged"
            @go-to-page="fpsNav.gotoPage" />
        </template>
        <template v-slot:body-cell-isMoved="props">
          <q-td :props="props" auto-width>
            <q-badge :color="props.row.isMoved ? 'positive' : 'red' " :label="props.row.isMoved ? '已完成' : '未完成'" />
          </q-td>
        </template>
      </q-table>
    </div>

    <q-dialog transition-hide="none" transition-show="none" v-model="showingUpdateLabelManagementDlg">
      <q-card style="max-width: 400px; width: 100%">
        <q-card-section class="q-pa-sm">
          <div class="text-h6">批量更新贴标工序管理信息</div>
        </q-card-section>
        <q-separator />
        <!--错误提示-->
        <q-banner class="text-white bg-red q-mt-sm q-mx-sm" dense inline-actions v-if="errorMessageForUpdateLabelManagement">
          {{ errorMessageForUpdateLabelManagement }}
          <template v-slot:action>
            <q-btn @click="errorMessageForUpdateLabelManagement = ''" dense flat icon="close" size="sm" />
          </template>
        </q-banner>
        <div class="q-pa-sm">
          <div class="row q-col-gutter-sm q-pt-sm">
            <div class="col-6">
              <span>拆装盒子</span>
              <easy-input v-model="$d.form.unpackBox" />
            </div>
            <div class="col-6">
              <span>拆中盒</span>
              <easy-input v-model="$d.form.unpackInnerBox" />
            </div>
            <div class="col-6">
              <span>拆塑封膜</span>
              <easy-input v-model="$d.form.tearOffSealingFilm" />
            </div>
            <div class="col-6">
              <span>贴内标</span>
              <easy-input v-model="$d.form.labelingInner" />
            </div>
            <div class="col-6">
              <span>贴内标小日期</span>
              <easy-input v-model="$d.form.labelingInnerSmallDate" />
            </div>
            <div class="col-6">
              <span>贴外标</span>
              <easy-input v-model="$d.form.labelingOuter" />
            </div>
            <div class="col-6">
              <span>喷码</span>
              <easy-input v-model="$d.form.sprayCode" />
            </div>
            <div class="col-6">
              <span>封口贴</span>
              <easy-input v-model="$d.form.sealSticker" />
            </div>
            <div class="col-6">
              <span>套袋子封口</span>
              <easy-input v-model="$d.form.bagAndSeal" />
            </div>
            <div class="col-6">
              <span>其它</span>
              <easy-input v-model="$d.form.other" />
            </div>
          </div>
        </div>
        <q-separator class="separator" />
        <q-card-actions align="right">
          <q-btn @click="doUpdateLabelManagement" color="primary" label="确定" :loading="updateLabelManagementState" />
          <q-btn color="primary" label="取消" outline unelevated v-close-popup :disable="updateLabelManagementState" />
        </q-card-actions>
      </q-card>
    </q-dialog>
  </q-page>
</template>
<script lang="ts">
export default {
  name: 'InvMoveItgStd',
}
</script>
<script lang="ts" setup>
import {useTitleHelper} from '@njt/foundation/hooks/titleHelper'
import {reactive, ref} from 'vue'
import {useFpsHelper} from '@njt/foundation/hooks/fpsHelper'
import {
  GetLabelInvMoveLineItgListReq,
  GetLabelInvMoveLineItgListResp,
  MhlInvMoveLineItg, UpdateLabelManagementByMoveLinesReq
} from 'src/defs/labelManagement'
import {ColumnInfo, FilterInfo} from '@njt/foundation/defs/comm'
import {WmWhLite} from '@njt/wms/defs/basic/wh.d'
import {MfLite} from '@njt/foundation/helper/dropdownlist.d'
import {WmZoneLite} from '@njt/wms/defs/basic/zone.d'
import {WmLoc} from '@njt/wms/defs/basic/loc'
import {WmSkuLite} from '@njt/wms/defs/basic/sku'
import _ from 'lodash'

const pageTitle = '贴标工单明细'
useTitleHelper(pageTitle)
let listDataLoadingState = ref(false)

let fpsReq: GetLabelInvMoveLineItgListReq = reactive({
  moveId: null,
  whId: null,
  storerId: null,
  docType: null,
  fZoneId: null,
  tZoneId: null,
  moveState: null,
  skuId: null,
  fLpn: null,
  tLpn: null,
  fLocId: null,
  tLocId: null,
  invLocId: null,
  vLot: null,
  lot: null,
  isMoved: null,
  pageNo: 1,
  pageSize: 40,
  isDescending: false,
  orderBy: null,
  sku: null
})

// 列参数
const columnsDefine: ColumnInfo[] = [
  {
    label: '明细ID',
    name: 'moveLineId',
    field: 'moveLineId',
    align: 'left',
    defOrder: 1,
    sortable: false,
    defVisible: true
  },
  {
    label: '主档ID',
    name: 'moveId',
    field: 'moveId',
    align: 'left',
    defOrder: 2,
    sortable: false,
    defVisible: true
  },
  {
    label: '仓库',
    name: 'whId',
    field: 'whId',
    align: 'left',
    defOrder: 3,
    sortable: false,
    defVisible: false
  },
  {
    label: '仓库名称',
    name: 'whName',
    field: 'whName',
    align: 'left',
    defOrder: 4,
    sortable: false,
    defVisible: true
  },
  {
    label: '货主',
    name: 'storerId',
    field: 'storerId',
    align: 'left',
    defOrder: 5,
    sortable: false,
    defVisible: false
  },
  {
    label: '货主名称',
    name: 'storerAbbrName',
    field: 'storerAbbrName',
    align: 'left',
    defOrder: 6,
    sortable: false,
    defVisible: true
  },
  {
    label: '移库原因',
    name: 'reason',
    field: 'reason',
    align: 'left',
    defOrder: 7,
    sortable: false,
    defVisible: true
  },
  {
    label: '状态',
    name: 'moveState',
    field: 'moveState',
    align: 'left',
    defOrder: 8,
    sortable: false,
    defVisible: true
  },
  {
    label: '来源储区',
    name: 'fZoneId',
    field: 'fZoneId',
    align: 'left',
    defOrder: 10,
    sortable: false,
    defVisible: true
  },
  {
    label: '来源储区名称',
    name: 'fZoneName',
    field: 'fZoneName',
    align: 'left',
    defOrder: 11,
    sortable: false,
    defVisible: true
  },
  {
    label: '目的储区',
    name: 'tZoneId',
    field: 'tZoneId',
    align: 'left',
    defOrder: 12,
    sortable: false,
    defVisible: true
  },
  {
    label: '目的储区名称',
    name: 'tZoneName',
    field: 'tZoneName',
    align: 'left',
    defOrder: 13,
    sortable: false,
    defVisible: true
  },
  {
    label: '移库方式',
    name: 'docType',
    field: 'docType',
    align: 'left',
    defOrder: 14,
    sortable: false,
    defVisible: true
  },
  {
    label: '计划移库日期',
    name: 'expectedDt',
    field: 'expectedDt',
    align: 'left',
    defOrder: 15,
    sortable: false,
    defVisible: true,
    format: (value: string) => $f.fmt.dtFmtDateOnly(value)
  },
  {
    label: '实际移库日期',
    name: 'moveDt',
    field: 'moveDt',
    align: 'left',
    defOrder: 16,
    sortable: false,
    defVisible: true,
    format: (value: string) => $f.fmt.dtFmtDateOnly(value)
  },
  {
    label: '审核时间',
    name: 'confirmDt',
    field: 'confirmDt',
    align: 'left',
    defOrder: 17,
    sortable: false,
    defVisible: true,
    format: (value: string) => $f.fmt.dtFmtFull(value)
  },
  {
    label: '审核人',
    name: 'confirmPn',
    field: 'confirmPn',
    align: 'left',
    defOrder: 19,
    sortable: false,
    defVisible: true,
    format: (confirmPn: string, row: MhlInvMoveLineItg) => $f.fmt.userDisp(row.confirmP as string, confirmPn)
  },
  {
    label: '库存序号',
    name: 'invLocId',
    field: 'invLocId',
    align: 'left',
    defOrder: 20,
    sortable: false,
    defVisible: true
  },
  {
    label: '料号ID',
    name: 'skuId',
    field: 'skuId',
    align: 'left',
    defOrder: 21,
    sortable: false,
    defVisible: true
  },
  {
    label: '料号',
    name: 'sku',
    field: 'sku',
    align: 'left',
    defOrder: 22,
    sortable: false,
    defVisible: true
  },
  {
    label: '品名',
    name: 'skuName',
    field: 'skuName',
    align: 'left',
    defOrder: 23,
    sortable: false,
    defVisible: true
  },
  {
    label: '英文品名',
    name: 'skuNameE',
    field: 'skuNameE',
    align: 'left',
    defOrder: 24,
    sortable: false,
    defVisible: true
  },
  {
    label: '规格型号',
    name: 'spec',
    field: 'spec',
    align: 'left',
    defOrder: 25,
    sortable: false,
    defVisible: true
  },
  {
    label: '批号',
    name: 'lot',
    field: 'lot',
    align: 'left',
    defOrder: 26,
    sortable: false,
    defVisible: true
  },
  {
    label: '外部批号',
    name: 'vLot',
    field: 'vLot',
    align: 'left',
    defOrder: 27,
    sortable: false,
    defVisible: true
  },
  {
    label: '数量',
    name: 'qty',
    field: 'qty',
    align: 'left',
    defOrder: 28,
    sortable: false,
    defVisible: true
  },
  {
    label: '来源储位ID',
    name: 'fLocId',
    field: 'fLocId',
    align: 'left',
    defOrder: 29,
    sortable: false,
    defVisible: false
  },
  {
    label: '来源储位编号',
    name: 'fLoc',
    field: 'fLoc',
    align: 'left',
    defOrder: 30,
    sortable: false,
    defVisible: true
  },
  {
    label: '来源栈板',
    name: 'fLpn',
    field: 'fLpn',
    align: 'left',
    defOrder: 31,
    sortable: false,
    defVisible: true
  },
  {
    label: '目的储位ID',
    name: 'tLocId',
    field: 'tLocId',
    align: 'left',
    defOrder: 32,
    sortable: false,
    defVisible: false
  },
  {
    label: '目的储位编号',
    name: 'tLoc',
    field: 'tLoc',
    align: 'left',
    defOrder: 33,
    sortable: false,
    defVisible: true
  },
  {
    label: '目的栈板',
    name: 'tLpn',
    field: 'tLpn',
    align: 'left',
    defOrder: 34,
    sortable: false,
    defVisible: true
  },
  {
    label: '是否移库完成',
    name: 'isMoved',
    field: 'isMoved',
    align: 'left',
    defOrder: 35,
    sortable: false,
    defVisible: true
  },
  {
    label: '明细状态',
    name: 'moveLineStateDisp',
    field: 'moveLineStateDisp',
    align: 'left',
    defOrder: 36,
    sortable: false,
    defVisible: true
  },
  {
    label: '操作日期',
    name: 'operateDt',
    field: 'operateDt',
    align: 'left',
    defOrder: 37,
    sortable: false,
    defVisible: true,
    format: (value: string) => $f.fmt.dtFmtFull(value)
  },
  {
    label: '操作人员',
    name: 'operateP',
    field: 'operateP',
    align: 'left',
    defOrder: 38,
    sortable: false,
    defVisible: true
  },
  {
    label: '操作人',
    name: 'operatePn',
    field: 'operatePn',
    align: 'left',
    defOrder: 39,
    sortable: false,
    defVisible: true,
    format: (operatePn: string, row: MhlInvMoveLineItg) => $f.fmt.userDisp(row.operateP as string, operatePn)
  },
  {
    label: '拆装盒子',
    name: 'unpackBox',
    field: 'unpackBox',
    align: 'left',
    defOrder: 40,
    sortable: false,
    defVisible: true,
  },
  {
    label: '拆中盒',
    name: 'unpackInnerBox',
    field: 'unpackInnerBox',
    align: 'left',
    defOrder: 41,
    sortable: false,
    defVisible: true,
  },
  {
    label: '拆塑封膜',
    name: 'tearOffSealingFilm',
    field: 'tearOffSealingFilm',
    align: 'left',
    defOrder: 42,
    sortable: false,
    defVisible: true,
  },
  {
    label: '贴内标',
    name: 'labelingInner',
    field: 'labelingInner',
    align: 'left',
    defOrder: 43,
    sortable: false,
    defVisible: true,
  },
  {
    label: '贴内标小日期',
    name: 'labelingInnerSmallDate',
    field: 'labelingInnerSmallDate',
    align: 'left',
    defOrder: 44,
    sortable: false,
    defVisible: true,
  },
  {
    label: '贴外标',
    name: 'labelingOuter',
    field: 'labelingOuter',
    align: 'left',
    defOrder: 45,
    sortable: false,
    defVisible: true,
  },
  {
    label: '喷码',
    name: 'sprayCode',
    field: 'sprayCode',
    align: 'left',
    defOrder: 46,
    sortable: false,
    defVisible: true,
  },
  {
    label: '封口贴',
    name: 'sealSticker',
    field: 'sealSticker',
    align: 'left',
    defOrder: 47,
    sortable: false,
    defVisible: true,
  },
  {
    label: '套袋子封口',
    name: 'bagAndSeal',
    field: 'bagAndSeal',
    align: 'left',
    defOrder: 48,
    sortable: false,
    defVisible: true,
  },
  {
    label: '其它',
    name: 'other',
    field: 'other',
    align: 'left',
    defOrder: 49,
    sortable: false,
    defVisible: true,
  },

]

const $d = reactive({
  tableData: [] as MhlInvMoveLineItg[],
  actualFieldShown: {
    fLocId: {
      isShown: true
    },
    tLocId: {
      isShown: true
    },
    sku: {
      isShown: true
    },
    fLpn: {
      isShown: true
    },
    tLpn: {
      isShown: true
    },
    moveId: {
      isShown: true
    },
    invLocId: {
      isShown: true
    },
    vLot: {
      isShown: true
    },
    lot: {
      isShown: true
    },
    isMoved: {
      isShown: true
    }
  },
  filterOptionList: {
    fLocId: {
      label: '来源储位',
      show: true,
      order: 1,
    },
    tLocId: {
      label: '目的储位',
      show: true,
      order: 2,
    },
    sku: {
      label: '料号',
      show: true,
      order: 3,
    },
    fLpn: {
      label: '来源栈板',
      show: true,
      order: 4,
    },
    tLpn: {
      label: '目的栈板',
      show: true,
      order: 5,
    },
    moveId: {
      label: '移库单ID',
      show: true,
      order: 6,
    },
    invLocId: {
      label: '库存ID',
      show: true,
      order: 7,
    },
    vLot: {
      label: 'LPN',
      show: true,
      order: 8,
    },
    lot: {
      label: '批号',
      show: true,
      order: 9,
    },
    isMoved: {
      label: '是否移库完成',
      show: true,
      order: 10,
    }
  } as Record<string, FilterInfo>,
  selectedItems: [] as MhlInvMoveLineItg[],
  // 仓库下拉
  whDropdownList: [] as WmWhLite[],
  // 货主
  storerDropdownList: [] as MfLite[],
  // 储区下拉
  zoneDropdownList: [] as WmZoneLite[],
  fLocIdDropdownList: [] as WmLoc[],
  tLocIdDropdownList: [] as WmLoc[],
  form: {} as UpdateLabelManagementByMoveLinesReq
})

const loadListData = function (resetFpsReq?: number) {
  if (resetFpsReq) {
    if (resetFpsReq >= 1) {
      fpsReq.pageNo = 1
    }
    if (resetFpsReq >= 2) {
      fpsReq.orderBy = ''
      fpsReq.isDescending = false
    }
  }
  listDataLoadingState.value = true
  $f.axios.get<GetLabelInvMoveLineItgListResp>('/project/mhlbc/inv/inventory/get-label-inv-move-line-itg-list', {params: fpsReq})
    .then((result) => {
      fpsAssist.handleGenericFpsResp(result.data)
      $d.tableData = result.data.mhlInvMoveLineItgs
      fpsAssist.saveFpsReq(fpsReq)
    })
    .catch((err) => {
      $f.ui.showNotifyFailed($f.getAxiosErrMsg(err))
    })
    .finally(() => {
      listDataLoadingState.value = false
    })
}

const {
  fpsInfo,
  fpsAssist,
  fpsNav,
  searchBarVisibility
} = useFpsHelper('/wms/sku/move-itg/',
  null,
  null,
  null,
  fpsReq, columnsDefine,
  $d.filterOptionList,
  loadListData)

// 仓库选择变更
const onWhChanged = function (value: number) {
  fpsReq.fZoneId = null
  fpsReq.tZoneId = null
  void $f.lst.getZoneSimpleList(value)
    .then((resp) => {
      $d.zoneDropdownList = resp.zones
    })
}
// 料号选择器返回
const onSkuSelected = function (skuInfo: WmSkuLite) {
  fpsReq.sku = skuInfo?.sku ?? null
  fpsReq.skuId = skuInfo?.skuId ?? null
}

let showingUpdateLabelManagementDlg = ref(false)
let errorMessageForUpdateLabelManagement = ref('')
// 批量更新按钮
const onUpdateLabelManagement = function () {
  $d.form.moveLineIds = _.map($d.selectedItems, 'moveLineId')
  $d.form.unpackBox = null
  $d.form.unpackInnerBox = null
  $d.form.tearOffSealingFilm = null
  $d.form.labelingInner = null
  $d.form.labelingInnerSmallDate = null
  $d.form.labelingOuter = null
  $d.form.sprayCode = null
  $d.form.sealSticker = null
  $d.form.bagAndSeal = null
  $d.form.other = null
  showingUpdateLabelManagementDlg.value = true
  errorMessageForUpdateLabelManagement.value = ''
}

// 执行状态
let updateLabelManagementState = ref(false)
// 执行批量更新
const doUpdateLabelManagement = () => {
  errorMessageForUpdateLabelManagement.value = ''
  updateLabelManagementState.value = true
  $f.axios.post('/project/mhlbc/inv/inventory/update-label-management-by-movelines', $d.form)
    .then(() => {
      loadListData()
      $d.selectedItems = []
      showingUpdateLabelManagementDlg.value = false
    })
    .catch((err) => {
      errorMessageForUpdateLabelManagement.value = $f.getAxiosErrMsg(err)
    })
    .finally(() => {
      updateLabelManagementState.value = false
    })
}

// 仓库下拉
void $f.lst.getWmWhSimpleList()
  .then((resp) => {
    $d.whDropdownList = resp
  })
// 货主下拉
void $f.lst.getMfSimpleList({isStorer: true})
  .then((resp) => {
    $d.storerDropdownList = resp.mfLiteList
  })
// 储区数据源
void $f.lst.getZoneSimpleList(null)
  .then((resp) => {
    $d.zoneDropdownList = resp.zones
  })
const fx = $f
</script>
